﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;
using bjcl_wmp.Models;

namespace bjcl_wmp.ViewModels
{
    class Playlist : ViewModelBase
    {
        public Library MyLibrary { get; set; }
        public Playlist()
        {
            this.MyLibrary = new Library();
        }

        private ObservableCollection<MyVideo> _Videos;
        public ObservableCollection<MyVideo> Videos
        {
            get
            {
                if (this._Videos == null)
                    this.Videos = new ObservableCollection<MyVideo>();
                this._Videos.Clear();
                this.MyLibrary.ImportLibrary("Playlist/playlist.xml");
                var result = from e in MyLibrary.Medias
                             where e.MyType == "video"
                             select e;
                foreach (var item in result)
                {
                    this._Videos.Add(new MyVideo() { Name = item.Name, MyUri = item.MyUri });
                }
                return this._Videos;
            }
            set
            {
                if (this._Videos != value)
                {
                    this._Videos = value;
                    OnPropertyChanged("Video");
                }
            }
        }

        private MyVideo _SelectedMedia;
        public MyVideo SelectedMedia
        {
            get
            {
                return this._SelectedMedia;
            }
            set
            {
                if (this._SelectedMedia != value)
                {
                    this._SelectedMedia = value;
                    OnPropertyChanged("SelectedMedia");
                }
            }
        }

        private ActionCommand _Command;
        public ActionCommand Command
        {
            get
            {
                if (this._Command == null)
                {
                    this._Command = new ActionCommand();
                    this._Command.Command = ChangedSelectedMedia;
                }
                return this._Command;
            }
        }

        public void ChangedSelectedMedia(object _param)
        {
            MyVideo item = _param as MyVideo;
            this.SelectedMedia = item;
        }

        //public ObservableCollection<MyImage> Images { get; set; }
        //public ObservableCollection<MyMusic> Musics { get; set; }
    }

    class MyVideo
    {
        public string Name { get; set; }
        public Uri MyUri { get; set; }
    }

    class MyImage
    {
        public string Name { get; set; }
        public Uri MyUri { get; set; }
    }

    class MyMusic
    {
        public string Name { get; set; }
        public Uri MyUri { get; set; }
    }
}
